package com.rules.admin.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rules.admin.dao.UserGroupDao;
import com.rules.admin.entity.UserGroup;
import com.rules.admin.service.UserGroupService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.stream.Collectors;

import java.util.List;

@Service
public class UserGroupServiceImpl extends ServiceImpl<UserGroupDao, UserGroup> implements UserGroupService {


    @Override
    public List<Long> getGroupIds(String userId) {
        LambdaQueryWrapper<UserGroup> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserGroup::getUserId, userId);
        List<UserGroup> userGroups = this.list(wrapper);
        if(CollectionUtil.isEmpty(userGroups)){
            return new ArrayList<>();
        }else{
            return userGroups.stream().map(UserGroup::getGroupId).collect(Collectors.toList());
        }

    }
}
